package myself.main.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import myself.login.service.LoginService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * 
 * 主界面 Controller
 * 
 * */
@Controller
public class MainController {
     
	Logger logger = LoggerFactory.getLogger(MainController.class);
	
	@Resource
	private LoginService loginService;
	
	//跳转到主界面
	@RequestMapping(value = "/studentMain.do")
	public ModelAndView main(HttpServletRequest request){
	
		HttpSession session = request.getSession();
		//取到session中的userCode的值
		String userCode = (String) session.getAttribute("userCode");
		//查询出userName的值
		String userName = loginService.qryStudentName(userCode);
		
		request.setAttribute("userName",userName);
		
		logger.info("成功跳转到学生主界面！");
		
		return new ModelAndView("WEB-INF/jsp/main/studentMain.jsp");
	}	
	
	@RequestMapping(value = "/teacherMain.do")
	public ModelAndView teacherMain(HttpServletRequest request){
		
		HttpSession session = request.getSession();
		
		String userCode = (String) session.getAttribute("userCode");
		
		String userName = loginService.qryteacherName(userCode);
		
//		System.out.println(userName);
		
		request.setAttribute("userName", userName);

        logger.info("成功跳转到教师主界面！");
		
		return new ModelAndView("WEB-INF/jsp/main/teacherMain.jsp");
	}
	
	@RequestMapping(value = "/ceshi.do")
	public ModelAndView ceshi(HttpServletRequest request){
		
		return new ModelAndView("WEB-INF/jsp/draw/draw.jsp");
	}
}
